package com.vonchange.common.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.vonchange.utils.config.SystemConfig;
import com.vonchange.utils.web.Result;

@Controller
@RequestMapping("/update")
public class UpdateController {
	private Log logger = LogFactory.getLog(UpdateController.class);

	@RequestMapping("/index")
	public String hello(HttpServletRequest request, HttpServletResponse response) {
		return "manage/update/index";
	}
	/**
	 * 更新配置文件
	 * 
	 * @param request
	 * @param response
	 * @return
	 */

	@RequestMapping("/config")
	@ResponseBody
	public Result config(HttpServletRequest request, HttpServletResponse response) {
		SystemConfig.initConfig();
		logger.info("配置文件已更新");
		return new Result().setMsg("配置已更新");
	}

	@RequestMapping("/getConfig")
	@ResponseBody
	public Result getConfig(@RequestParam("key") String key, HttpServletRequest request, HttpServletResponse response) {
		return new Result().setResult(SystemConfig.getProperty(key));
	}

	@RequestMapping("/resRelease/{flag}")
	@ResponseBody
	public Result resRelease(@PathVariable("flag") Boolean flag, HttpServletRequest request, HttpServletResponse response) {
		if (null != flag && flag == true) {
			SystemConfig.systemProperties.put("res.release", "true");
		} else {
			SystemConfig.systemProperties.put("res.release", "false");
		}
		return new Result().setResult(SystemConfig.getProperty("res.release")).setMsg("修改资源显示模式成功");
	}

}
